//
// Created by ZLY on 2025/5/10.
//

#include "spawner.h"

#include "enemy.h"
#include "core/scene.h"

void Spawner::update(float dt) {
    Object::update(dt);
    if (!target_ || !target_->getActive()) {
        return;
    }
    timer_ += dt;
    if (timer_ >= interval_) {
        timer_ = 0;
        game_.playSound("resources/sound/silly-ghost-sound-242342.mp3");
        for (int i = 0; i < num_; i++) {
            auto pos = game_.randomVec2(game_.getCurrentScene()->getCameraPos(),
                                        game_.getCurrentScene()->getCameraPos() + game_.getScreenSize());
            auto enemy = Enemy::addEnemyChild(nullptr, pos, target_);
            Effect::addEffectChild(game_.getCurrentScene(), "resources/effect/184_3.png", pos, 1.0f, enemy);
        }
    }
}
